<?php
	require("includes/basic.php");

	$project=addslashes($_POST['project']);
	$pro_desc=addslashes($_POST['project-desc']);
	$creator=$userId;
	$client=$_POST['client'];

	//mkdir("Projects/".$project);
	//$target_path = "Projects/".$project."/";



	$sql1=mysql_query("insert into project_master (`project_name`,`project_description`,`project_created_on`,`project_created_by`) values ('$project','$pro_desc',sysdate(),'$creator')");

	if($sql1)
	{
		$getproid=mysql_query("SELECT * FROM project_master order by project_id desc limit 1");
		$proidr=mysql_fetch_array($getproid);
		extract($proidr);
		$proid=$proidr['project_id'];
		if(isset($_POST['submit']) && $_FILES['uploadedfile']['size'] > 0)
			{

				$fileName = $_FILES['uploadedfile']['name'];
				$tmpName = $_FILES['uploadedfile']['tmp_name'];
				$fileSize = $_FILES['uploadedfile']['size'];
				$fileType = $_FILES['uploadedfile']['type'];
				echo $fileType;
				echo $tmpName;
				$fp      = fopen($tmpName, 'r');
				$content = fread($fp, filesize($tmpName));
				$content = addslashes($content);
				fclose($fp);

				if(!get_magic_quotes_gpc())
				{
					$fileName = addslashes($fileName);
				}

				$query = "INSERT INTO project_doc (name, size, type, content, project_id, uploaded_on, uploaded_by) VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$proid', sysdate(), '$creator')";

				mysql_query($query) or die('Error, query failed'); 

				$filePath = $target_path . $fileName;

				//$result = move_uploaded_file($tmpName, $filePath);
				//if (!$result) {
				//echo "Error uploading file";
				//exit;
				//}
				//echo "uploaded";
			}
			
			if(isset($_POST['submit']) && $_FILES['file']['size'] > 0)
			{

				$fileName1 = $_FILES['file']['name'];
				$tmpName1 = $_FILES['file']['tmp_name'];
				$fileSize1 = $_FILES['file']['size'];
				$fileType1 = $_FILES['file']['type'];

				$fp1      = fopen($tmpName1, 'r');
				$content1 = fread($fp, filesize($tmpName1));
				$content1 = addslashes($content1);
				fclose($fp1);

				if(!get_magic_quotes_gpc())
				{
					$fileName1 = addslashes($fileName1);
				}

				$query = "INSERT INTO project_doc (name, size, type, content, project_id, uploaded_on, uploaded_by) VALUES ('$fileName1', '$fileSize1', '$fileType1', '$content1', '$proid', sysdate(), '$creator')";

				mysql_query($query) or die('Error, query failed'); 

				$filePath = $target_path . $fileName;

				//$result = move_uploaded_file($tmpName, $filePath);
				//if (!$result) {
				//echo "Error uploading file";
				//exit;
				//}
				//echo "uploaded";
			}



	if(isset($_POST['submit']) && $_FILES['file2']['size'] > 0)
			{

				$fileName2 = $_FILES['file2']['name'];
				$tmpName2 = $_FILES['file2']['tmp_name'];
				$fileSize2 = $_FILES['file2']['size'];
				$fileType2 = $_FILES['file2']['type'];

				$fp2      = fopen($tmpName2, 'r');
				$content2 = fread($fp2, filesize($tmpName2));
				$content2 = addslashes($content2);
				fclose($fp2);

				if(!get_magic_quotes_gpc())
				{
					$fileName2 = addslashes($fileName2);
				}

				$query = "INSERT INTO project_doc (name, size, type, content, project_id, uploaded_on, uploaded_by) VALUES ('$fileName2', '$fileSize2', '$fileType2', '$content2', '$proid', sysdate(), '$creator')";

				mysql_query($query) or die('Error, query failed'); 

				$filePath = $target_path . $fileName;

				//$result = move_uploaded_file($tmpName, $filePath);
				//if (!$result) {
				//echo "Error uploading file";
				//exit;
				//}
				//echo "uploaded";
			}



	if(isset($_POST['submit']) && $_FILES['file3']['size'] > 0)
			{

				$fileName3 = $_FILES['file3']['name'];
				$tmpName3 = $_FILES['file3']['tmp_name'];
				$fileSize3 = $_FILES['file3']['size'];
				$fileType3 = $_FILES['file3']['type'];

				$fp3      = fopen($tmpName3, 'r');
				$content3 = fread($fp3, filesize($tmpName3));
				$content3 = addslashes($content3);
				fclose($fp3);

				if(!get_magic_quotes_gpc())
				{
					$fileName3 = addslashes($fileName3);
				}

				$query = "INSERT INTO project_doc (name, size, type, content, project_id, uploaded_on, uploaded_by) VALUES ('$fileName3', '$fileSize3', '$fileType3', '$content3', '$proid', sysdate(), '$creator')";

				mysql_query($query) or die('Error, query failed'); 

				$filePath = $target_path . $fileName;

				//$result = move_uploaded_file($tmpName, $filePath);
				//if (!$result) {
				//echo "Error uploading file";
				//exit;
				//}
				//echo "uploaded";
			}



	if(isset($_POST['submit']) && $_FILES['file4']['size'] > 0)
			{

				$fileName4 = $_FILES['file4']['name'];
				$tmpName4 = $_FILES['file4']['tmp_name'];
				$fileSize4 = $_FILES['file4']['size'];
				$fileType4 = $_FILES['file4']['type'];

				$fp4      = fopen($tmpName4, 'r');
				$content4 = fread($fp4, filesize($tmpName4));
				$content4 = addslashes($content4);
				fclose($fp4);

				if(!get_magic_quotes_gpc())
				{
					$fileName4 = addslashes($fileName4);
				}

				$query = "INSERT INTO project_doc (name, size, type, content, project_id, uploaded_on, uploaded_by) VALUES ('$fileName4', '$fileSize4', '$fileType4', '$content4', '$proid', sysdate(), '$creator')";

				mysql_query($query) or die('Error, query failed'); 

				$filePath = $target_path . $fileName;

				//$result = move_uploaded_file($tmpName, $filePath);
				//if (!$result) {
				//echo "Error uploading file";
				//exit;
				//}
				//echo "uploaded";
			}



	if(isset($_POST['submit']) && $_FILES['file5']['size'] > 0)
			{

				$fileName5 = $_FILES['file5']['name'];
				$tmpName5 = $_FILES['file5']['tmp_name'];
				$fileSize5 = $_FILES['file5']['size'];
				$fileType5 = $_FILES['file5']['type'];

				$fp5      = fopen($tmpName5, 'r');
				$content5 = fread($fp5, filesize($tmpName5));
				$content5 = addslashes($content5);
				fclose($fp5);

				if(!get_magic_quotes_gpc())
				{
					$fileName5 = addslashes($fileName5);
				}

				$query = "INSERT INTO project_doc (name, size, type, content, project_id, uploaded_on, uploaded_by) VALUES ('$fileName5', '$fileSize5', '$fileType5', '$content5', '$proid', sysdate(), '$creator')";

				mysql_query($query) or die('Error, query failed'); 

				$filePath = $target_path . $fileName;

				//$result = move_uploaded_file($tmpName, $filePath);
				//if (!$result) {
				//echo "Error uploading file";
				//exit;
				//}
				//echo "uploaded";
			}







		$sql=mysql_query("insert into client_project (`project_id`,`client_id`) values ('$proid','$client')");

	}


			if($sql)
			{
			 header("location:view-projects.php");
			}
			ob_flush();
?>